package top.fzqblog.firstapp;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;

/**
 * Created by 抽离 on 2017/8/16 0016.
 */

public class WebViewTest extends Activity {

    WebView webView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webviewtest);
        webView = (WebView) findViewById(R.id.searchResult);
        Button button_search = (Button) findViewById(R.id.search);
        button_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EditText editText = (EditText)findViewById(R.id.searchUrl);
                webView.loadUrl(editText.getText().toString());
                WebSettings settings = webView.getSettings();
                settings.setJavaScriptEnabled(true);
                webView.setWebViewClient(new WebViewClient());
            }
        });
    }

    @Override
    public void onBackPressed() {
        if(webView.canGoBack()){
            webView.goBack();
        }else {
            super.onBackPressed();
        }
    }
}
